#ifndef _CRT_SECURE_NO_WARNINGS
	#define _CRT_SECURE_NO_WARNINGS // Deal with warnings in glui.h
#endif

#include "Views.h"

#include "boards/BoardModelling.h"

int current_camera_idx = CAMERA1_IDX;

void setCamP1(void);
void setCamP2(void);
void setCam3(void);
void setCam4(void);

Camera cams[] = { {CAMERA1_IDX, setCamP2, "Player 1"},
				  {CAMERA2_IDX, setCamP1, "Player 2"},
				  {CAMERA3_IDX, setCam3, "Overview"},
				  {CAMERA3_IDX, setCam4, "Freestyle"}
				};

GLdouble camP1[3][3] = {
	{ BENCH_BOARD_TRANSLATE_X, CAMERA_HEIGHT, BENCH_BOARD_TRANSLATE_Z + BENCH_BOARD_DIM_Z}, // EYE
	{ 0.0, 0.0, 0.0}, // CENTER
	{0.0, 1.0, 0.0} // UP
};

GLdouble camP2[3][3] = {
	{BENCH_BOARD_TRANSLATE_X, CAMERA_HEIGHT, -(BENCH_BOARD_TRANSLATE_Z + BENCH_BOARD_DIM_Z)},
	{0.0, 0.0, 0.0},
	{0.0, 1.0, 0.0}
};

GLdouble cam3[3][3] = {
	{BOARD_DIM_X, CAMERA_HEIGHT, 0.0},
	{0.0, 0.0, 0.0},
	{0.0, 1.0, 0.0}
};

float obj_pos[] = { 0.0, 0.0, 0.0 };
float view_rotate[16] = { 1,0,0,0,
                          0,1,0,0,
                          0,0,1,0,
                          0,0,0,1 };

void setCamP1() {
	gluLookAt(camP1[CAM_EYE_IDX][0],	 camP1[CAM_EYE_IDX][1],	   camP1[CAM_EYE_IDX][2], 
			  camP1[CAM_CENTER_IDX][0],  camP1[CAM_CENTER_IDX][1], camP1[CAM_CENTER_IDX][2],
			  camP1[CAM_UP_IDX][0],		 camP1[CAM_UP_IDX][1],	   camP1[CAM_UP_IDX][2]
	);
}

void setCamP2() {
	gluLookAt(camP2[CAM_EYE_IDX][0],	 camP2[CAM_EYE_IDX][1],	   camP2[CAM_EYE_IDX][2], 
			  camP2[CAM_CENTER_IDX][0],  camP2[CAM_CENTER_IDX][1], camP2[CAM_CENTER_IDX][2],
			  camP2[CAM_UP_IDX][0],		 camP2[CAM_UP_IDX][1],	   camP2[CAM_UP_IDX][2]
	);
}

void setCam3() {
	gluLookAt(cam3[CAM_EYE_IDX][0],	    cam3[CAM_EYE_IDX][1],	   cam3[CAM_EYE_IDX][2], 
			  cam3[CAM_CENTER_IDX][0],  cam3[CAM_CENTER_IDX][1],   cam3[CAM_CENTER_IDX][2],
			  cam3[CAM_UP_IDX][0],		cam3[CAM_UP_IDX][1],	   cam3[CAM_UP_IDX][2]
	);
}

void setCam4() {
	glTranslatef( obj_pos[0], obj_pos[1], -obj_pos[2]-100.0 );
	glRotated( 20.0, 1.0,0.0,0.0 );
	glRotated(-20.0, 0.0,1.0,0.0 );
	glMultMatrixf( view_rotate );
}

void showCamId(char *cam_id) {
	int length = strlen(cam_id);
	
	// Sets Projection and Modelview matrices for 2D Rendering
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
		glLoadIdentity();
		gluOrtho2D(0.0, 100.0, 0.0, 100.0);

		glMatrixMode(GL_MODELVIEW);
		glPushMatrix();
			glLoadIdentity();

			glDisable(GL_LIGHTING);
			glColor3f(1.0, 1.0, 1.0);
			glRasterPos2f(1.0, 100.0 - 5.0);
			for(int i = 0; i < length; ++i) {
				glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, cam_id[i]);
			}

			// glRasterPos2f(1.0, 100.0 - 10.0);
			// glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, 'O');
			
			glEnable(GL_LIGHTING);
			glMatrixMode(GL_MODELVIEW); // Resets the Matrices for 3D Rendering
		glPopMatrix();
		glMatrixMode(GL_PROJECTION);
	glPopMatrix();
}